package sysAuth

class SysFunOpt {

    SysFunctions function;
    SysOperations operate;
    String action;
    int state = 1

    static constraints = {
        function(nullable: false,blank: false,unique: "operate" )
        operate(nullable: false,blank: false)
        action(nullable:true)
        state(inList: [1,0])
    }
    static mapping = {
        version false
    }

    static init(){
        if(SysFunOpt.count() == 0){

            SysOperations.findAllByOperateNoInList(['del','add','query','downLoad','upLoad','addAuth','edit']).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_USER"),operate: it).save(flush: true)
            }

            SysOperations.findAllByOperateNoInList([ 'add' ]).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_OPERATE"),operate: it).save(flush: true)
            }

            SysOperations.findAllByOperateNoInList([ 'query','test','add','downLoad','del' ]).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_SOURCE"),operate: it).save(flush: true)
            }

            SysOperations.findAllByOperateNoInList([ 'query' ,'add','downLoad','del','edit','copy' ]).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_PARAMS"),operate: it).save(flush: true)
            }

            //updateRead,updateReadAll,del,addPublicNoice,addPrivateNotice
            SysOperations.findAllByOperateNoInList([ 'updateRead' ,'updateReadAll','del','addPublicNotice' ]).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_NOTICE"),operate: it).save(flush: true)
            }

            SysOperations.findAllByOperateNoInList([ 'del','edit','add','query' ]).each {
                new SysFunOpt(function: SysFunctions.findByFuncNo("SYS_WIDGET1"),operate: it).save(flush: true)
            }
        }
    }
}
